package cn.starremote.component.utils.encrypt;

import org.junit.jupiter.api.Test;

import java.util.Map;

import static org.junit.jupiter.api.Assertions.*;

class RSAUtilsTest {

    private static final String PUBLIC_KEY_NAME = "publicKey";
    private static final String PRIVATE_KEY_NAME = "privateKey";

    @Test
    void verifySign() {
        Map<String, String> keyPairMap = RSAUtils.createRSAKeys();
        System.out.println("生成公、私钥测试："+keyPairMap);

        String publicKey = keyPairMap.get(PUBLIC_KEY_NAME);
        String privateKey = keyPairMap.get(PRIVATE_KEY_NAME);

        System.out.println("RSA公钥="+publicKey);
        System.out.println("RSA私钥="+privateKey);
        System.out.println("===开始RSA公、私钥测试===");
        String str = "alpha=001&beta=002&gamma=003";

        String content = "merAttach=备注&merSubmitTime=20190912135509&merchantNo=C10000&msgCipherText=wwwe34343&signType=1&transCode=b2bPay&transVersion=1.0";

        String sign = RSAUtils.sign(privateKey, str);
        System.out.println("sign测试="+sign);
        boolean verifyFlg = RSAUtils.verifySign(publicKey, str, sign);
        System.out.println("verifyFlg="+verifyFlg);


        String encrypt = RSAUtils.rsaEncryptByPub(content,publicKey);
        System.out.println("加密串：" + encrypt);

        String decrypt = RSAUtils.rsaDecryptByPri(encrypt,privateKey);
        System.out.println("解密串：" + decrypt);

    }
}